var express = require('express');
var mongoose = require('mongoose');
mongoose.connect("mongodb://121.42.157.17:27017/test", {useMongoClient: true});

var router = express.Router();

const jobListSchema = new mongoose.Schema({
    "id" : String,
    "place" : String,
    "title" : String,
    "timeFrom" : String,
    "timeTo" : String,
    "hireCount" : Number,
    "duration" : Number,
    "salary" : Number,
    "commission1" : Number,
    "commission2" : Number,
    "deposit" : Number,
    "description" : String,
    "type" : Number,
    "status" : Number,
    "region" : String
}, {collection: 'viewjob'});

const jobListModel = mongoose.model('jobList', jobListSchema);

var response = {
    "value": [],
    "errorCode": "200",
    "message": null
};

router.post('/', function(req, res, next) {
    console.log(req.body);
    let limitNum = req.body.size;
    let skipNum = req.body.page * req.body.size;

    jobListModel.find({}, function(err, result) {
        if(err) return console.log(err);
        response.value = result;
        res.send(JSON.stringify(response));
    }).limit(limitNum).skip(skipNum);
});

module.exports = router;